import { ProductList } from '../product/list-model.js';
var productList = new ProductList();
Page({

  data: {
    page:1,
    productData:[]
  },
  onLoad: function (options) {
    this.getProduct();
  },

  onReady: function () {

  },
  getProduct: function () {
    var that = this
    var params = {
      'num': 10,
    }
    //获取热销数据
    this.setData({
      searchLoading: true,
    })
    productList.getProductData(this.data.page, '', params, (data) => {
      var mydata = that.data.productData.concat(data.items);
      that.setData({
        productData: mydata,
        pageCount: data._meta.pageCount,
      })
      if (data._meta.pageCount <= 1) {
        this.setData({
          searchLoading: false,
          searchLoadingComplete: true,
        })
      }
      if (data._meta.pageCount <= that.data.page) {
        this.setData({
          searchLoading: false,
          searchLoadingComplete: true,
        })
      }
    });
  },
  onPullDownRefresh: function () {

  },
  goto: function (e) {
    var url = e.currentTarget.dataset.url;
    wx.redirectTo({
      url: url,
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})